﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using EntityLayer0;




namespace DataAccess
{


    public class LoginDAL
    {
        private string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Joyce\Documents\Oefenproject.mdf;Integrated Security=True;Connect Timeout=30";

        private DataTable dataTable = new DataTable();
 

        public LoginDAL()
        {
           
        }

        public DataTable login(string username, string password)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            string command = "SELECT * FROM UserData WHERE UserName = '" + username + "' and Password = '" + password + "'";
            SqlDataAdapter adapter = new SqlDataAdapter(command, connectionString);
            adapter.Fill(dataTable);
            return dataTable;
        }

        public DataTable GetRecorder()
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            string command = "SELECT * FROM RECORDERS WHERE DEVICEID = 1";
            SqlDataAdapter adapter = new SqlDataAdapter(command, connectionString);
            adapter.Fill(dataTable);
            return dataTable;
        }


        public void AddRecorder(RecorderInfo recorderInfo)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            SqlCommand command = new SqlCommand("INSERT INTO RECODERS (DEVICEID, RECORDERNAME, RECORDERSERIAL) VALUES('" + recorderInfo.DeviceId +"', '" +recorderInfo.RecorderName+"', '" +recorderInfo.RecorderSerial+"')", sqlConnection);
            command.ExecuteNonQuery();
        }

        public DataTable GetFileInfo()
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            string command = "SELECT * FROM FileInfo WHERE FileId = 1";
            SqlDataAdapter adapter = new SqlDataAdapter(command, connectionString);
            adapter.Fill(dataTable);
            return dataTable;
        }

        public void AddFileInfo(FileDataInfo fileDataInfo, long deviceID)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            SqlCommand command = new SqlCommand("INSERT INTO FileInfo (FileId, FileName, FileFormat, Hash, deviceID) VALUES('" + fileDataInfo.FileId + "', '" + fileDataInfo.FileName + "', '" + fileDataInfo.FileFormat + "', '" + fileDataInfo.FirstHash + "', '" + deviceID +"')", sqlConnection);
            command.ExecuteNonQuery();           
        }

        


    }
}
